<?php

namespace App\Http\Requests\Admin\Wechat\Menu;

use App\Http\Requests\Admin\Request;

class UpdateRequest extends Request
{

    public function rules()
    {
        
         $url = "^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-";   
        $url .= "Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{";   
        $url .= "2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}";   
         $url .= "[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|";   
         $url .=  "[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-";   
         $url .=  "4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0";   
         $url .=  "-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/";   
         $url .=  "[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&%\\$\\=~_\\-@]*)*$";   
        return [
            'name' => 'required|max:5',
            //'url'=>array('regex:/(http?|ftp?):\/\/(www)\.([^\.\/]+)\.(com|cn)(\/[\w-\.\/\?\%\&\=]*)?/i')
            '$url'=>$url
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '名称必须填写',
            'name.max' => '名称最长为5个字符',
            'name.unique' => '名称已存在',
            'url.regex'=>"网址格式不正确"
        ];
    }
}
